package com.example.studyplanning.controller;

import com.example.studyplanning.entity.Dislike;
import com.example.studyplanning.entity.Like;
import com.example.studyplanning.services.DislikeServices;
import com.example.studyplanning.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("dislike")
public class DislikeController {
    @Autowired
    private DislikeServices dislikeServices;

    //拉黑心得
    @PostMapping("/add")
    public Result InsertDislike(@RequestBody Dislike dislike){
        Result result = new Result();
        int i =dislikeServices.InsertDislike(dislike);
        if(i==1){
            result.setCode(200);
            result.setMessage("拉黑成功");
        }else{
            result.setCode(400);
            result.setMessage("拉黑失败");
        }
        return result;
    };

    //展示拉黑信息
    @GetMapping("/list")
    public Result FindDislike(@RequestParam("userID") Integer userID,
                           @RequestParam("tipsID") Integer tipsID){
        Result result = new Result();
        List<Dislike> list = dislikeServices.FindDislike(userID,tipsID);
        if(list.size()==0){
            result.setCode(400);
            result.setMessage("未拉黑");}
        else {
            result.setCode(200);
            result.setMessage("已拉黑");
        }
        return result;
    };


    //取消拉黑
    @GetMapping("/del")
    public Result DelDislike(@RequestParam("userID") Integer userID,
                             @RequestParam("tipsID") Integer tipsID){
        Result result = new Result();
        int i = dislikeServices.DelDislike(userID,tipsID);
        if (i==1){
            result.setCode(200);
            result.setMessage("删除成功");
        }else {
            result.setCode(400);
            result.setMessage("删除失败");
        }
        return result;
    };
}
